package com.fit.pages.homeworkRecords;

import java.util.List;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.annotations.AdminAccess;
import com.fit.annotations.AnonymousAccess;
import com.fit.annotations.ProfessorAccess;
import com.fit.annotations.StudentAccess;
import com.fit.dao.homework.HomeworkDAO;
import com.fit.dao.homeworkRecords.HomeworkRecordsDAO;
import com.fit.dao.classes.ClassesDAO;
import com.fit.dao.course.CourseDAO;
import com.fit.dao.studentOfTheCourse.StudentOfTheCourseDAO;
import com.fit.dao.user.UserDAO;
import com.fit.entities.homework.Homework;
import com.fit.entities.homeworkRecords.HomeworkRecords;
import com.fit.entities.classes.Classes;
import com.fit.entities.course.Course;
import com.fit.entities.studentOfTheCourse.StudentOfTheCourse;
import com.fit.entities.user.User;
import com.fit.pages.ErrorPage;

@AdminAccess
@AnonymousAccess
@ProfessorAccess
@StudentAccess
public class Browse {

	@Property
	private List<HomeworkRecords> homeworkRecordss;
	@Property
	private HomeworkRecords homeworkRecords;
	@Inject
	private HomeworkRecordsDAO homeworkRecordsDAO ;
	@InjectPage
	private ErrorPage errorPage;

	void onActivate() {
		homeworkRecordss = homeworkRecordsDAO.findAll();
	}

	@OnEvent(component = "deleteLink")
	Object onDeleteLink(Long id) {
		try {
			homeworkRecordsDAO.deleteByID(id);
			return null;
		} catch (Exception e) {
			errorPage.setMessage("Error while trying to delete Homework from the records! ");
			return errorPage;
		}
	}
}
